package com.huike.review.service.impl;

import com.huike.common.constant.Constants;
import com.huike.common.constant.UserConstants;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.exception.CustomException;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import com.huike.review.mapper.MybatisReviewMapper;
import com.huike.review.vo.MybatisReviewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * mybatis复习使用的业务层
 * 注意该业务层和我们系统的业务无关，主要是让同学们快速熟悉系统的
 */
@Service
public class ReviewServiceImpl implements ReviewService {

    @Autowired
    private MybatisReviewMapper reviewMapper;

    //单条件查询
    @Override
    public Review getById(Long id) {
        return reviewMapper.selectById(id);
    }

    //分页查询
    @Override
    public List<Review> getDataList() {
        return reviewMapper.getDataList();
    }

    //get新增
    @Override
    public int saveData(String name, Integer age, String sex) {
        //1.补全信息
        Review review = new Review();
        review.setName(name);
        review.setAge(age);
        review.setSex(sex);
        //review.setCreateBy(SecurityUtils.getUsername());
        review.setCreateBy(UserConstants.SYS_USER);
        review.setCreateTime(DateUtils.getNowDate());
        review.setUpdateBy(UserConstants.SYS_USER);
        review.setUpdateTime(DateUtils.getNowDate());
        //2.调用mapper层
        return reviewMapper.saveData(review);
    }

    //post新增
    @Override
    public int savePostData(Review review) {
        //调用mapper
        return reviewMapper.savePostData(review);
    }

    //根据id修改
    @Override
    public int update(Review review) {
        //补全信息
        //1.设置修改人
        review.setUpdateBy(UserConstants.SYS_USER);
        //2.设置修改时间
        review.setUpdateTime(DateUtils.getNowDate());
        //3.调用mapper层
        return reviewMapper.update(review);
    }

    //根据id删除
    @Override
    public int remove(Long id) {
        //调用mapper层
        return reviewMapper.remove(id);
    }


}
